<template>
  <section class="app-inner">
    <el-card class="header-card">
      <el-form :inline="true" :model="queryParams" size="small" label-width="84px">
        <el-form-item label="教室名称">
          <el-input clearable placeholder="请输入教室名称" v-model="queryParams.name"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="searchData">查询</el-button>
          <el-button @click="handleAdd" type="primary" icon="plus" size="small">新增</el-button>
        </el-form-item>
      </el-form>
      <div id="main1" class="main1Echart"></div>
    </el-card>
  </section>
</template>

<script>
import * as echarts from 'echarts'
import { getClassRoomInfoList, deleteClassRoomInfo } from './js/classRoomInfo'
export default {
  name: 'classroomInfo',
  data () {
    return {
      pageNum: 1,
      pageSize: 10,
      totalPageNum: 1,
      tableData: [],
      queryParams: {},
      eqptTypeList: [],
      classroomTypeList: []
    }
  },
  mounted () {
    this.getClassRoomInfoList()
    var chartDom1 = document.getElementById('main1')
    var myChart1 = echarts.init(chartDom1)
    var option1 = {}
    option1 = {
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [820, 932, 901, 934, 1290, 1330, 1320],
          type: 'line',
          areaStyle: {},
          markLine: {
            data: [{ type: 'average', name: 'Avg' }]
          }
        }
      ]
    }
    option1 && myChart1.setOption(option1)
  },
  methods: {
    cons (scope) {
      console.log(scope)
    },
    // 查询按钮
    searchData () {
      this.pageNum = 1
      this.getClassRoomInfoList()
    },
    // 新增
    handleAdd () {
      this.$refs.classroomInfoModal.isAdd = true
      this.$refs.classroomInfoModal.add()
    },
    modalOk () {
      this.getClassRoomInfoList()
    },
    // 分页
    pageHandleChange (page) {
      this.pageNum = page
      this.getClassRoomInfoList()
    },
    async getClassRoomInfoList () {
      const params = {
        pageNum: this.pageNum,
        pageSize: this.pageSize
      }
      // this.queryParams,
      const data = Object.assign({}, this.queryParams, params)
      let res = await getClassRoomInfoList(data)
      console.log(res)
      this.tableData = res.data.records
      this.totalPageNum = res.data.total
    },
    // 编辑
    handleEdit (row) {
      this.$refs.classroomInfoModal.isAdd = false
      this.$refs.classroomInfoModal.edit(row)
    },
    // 删除
    handleDelete (row) {
      this.$confirm('您确定删除当前教室, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.deleteFun(row)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    async deleteFun (row) {
      let res = await deleteClassRoomInfo(row.id)
      if (res.code === 0) {
        if (this.tableData.length === 1 && this.pageNum > 1) {
          this.pageNum--
        }
        this.$message.success('删除成功!')
        this.getClassRoomInfoList()
      } else {
        this.$message.error(res.msg)
      }
    }
  }
}
</script>

<style scoped>
.main1Echart {
  width: 100%;
  height: 250px;
}
</style>
